﻿using System.Collections.Generic;
using System.Xml.Linq;
using QASPRibbon.Commands;
using Schema = QASPRibbon.RibbonSchema;

namespace QASPRibbon.Controls
{
    /// <summary>
    /// Represents a ToggleButton control in the SharePoint Server Ribbon. 
    /// </summary>
    public class RibbonToggleButton : RibbonButton
    {
        internal override string XmlTag
        {
            get { return Schema.ToggleButton; }
        }

        internal override IEnumerable<RibbonCommand> ClientCommands
        {
            get
            {
                var res = new List<RibbonCommand>
                              {
                                  new RibbonCommand(FullId, Schema.CheckState,
                                                    OnClientStateCheck,
                                                    Enabled ? "; return true;" : "; return false;"),
                                  new RibbonCommand(FullId, Schema.Command, string.Format("{0};", OnClientClick ?? string.Empty)),
                                  new RibbonCommand(FullId, Schema.QueryCommand, string.Format("{0};", OnClientActivate ?? string.Empty))
                              };
                return res;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public RibbonToggleButton() { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        public RibbonToggleButton(string id) : base(id) { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="title"></param>
        public RibbonToggleButton(string id, string title) : base(id, title) { }

        internal override XElement AsXElement()
        {
            var res = base.AsXElement();
            res.Add(new XAttribute(Schema.QueryCommand, FullId + Schema.QueryCommand));
            return res;
        }
    }
}
